package com.xuecheng.system.web.exception;

import com.xuecheng.commons.enums.ErrorCode;
import com.xuecheng.commons.model.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = RuntimeException.class)
    public ResponseResult handerRuntimeException(RuntimeException e) {
        log.error(e.getMessage());
        return ResponseResult.errorResult(ErrorCode.ERROR);
    }

    @ExceptionHandler(value = BusinessException.class)
    public ResponseResult handBusinessException(BusinessException e) {
        ErrorCode code = e.getCode();
        return ResponseResult.errorResult(code);
    }
}
